package com.talktalk.frame;

import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.LayoutManager;

import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.border.LineBorder;

public class TestFrame extends JFrame{

	public static void main(String[] args) {
		new TestFrame();
	}
	
	LayoutManager listLayout = new LayoutManager() {
		
		
		
		@Override
		public void removeLayoutComponent(Component comp) {
			// TODO Auto-generated method stub
			
		}
		
		@Override
		public Dimension preferredLayoutSize(Container parent) {
			Component[] components = parent.getComponents();
			Component component = components[0];
			if(component == null){
				return new Dimension(0, 0);
			}
			Dimension dimension = new Dimension(parent.getWidth()
					, component.getHeight()*components.length);
			return dimension;
		}
		
		@Override
		public Dimension minimumLayoutSize(Container parent) {
			return null;
		}
		
		@Override
		public void layoutContainer(Container parent) {
			Component[] components = parent.getComponents();
			for(int i = 0;i<components.length;i++){
				components[i].setLocation(0,components[i].getHeight()*i);
			}
		}
		
		@Override
		public void addLayoutComponent(String name, Component comp) {
			
		}
	};
	
	public TestFrame() {
		JPanel panel = new JPanel();
		panel.setLayout(new ListLayout());
		JScrollPane jsp = new JScrollPane(panel);
		
		for(int i = 0;i<4;i++){
			JLabel lab = new JLabel(i+"");
			lab.setSize(300,50);
			lab.setBorder(new LineBorder(Color.black));
			lab.setBackground(Color.blue);
			panel.add(lab);
		}
		
		this.getContentPane().add(jsp);
		this.setSize(300, 600);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setVisible(true);
	}
	
}	
